package com.pm.main.controller;

import com.pm.main.common.PageReq;
import com.pm.main.common.PageRsp;
import com.pm.main.controller.req.CommoditySearchReq;
import com.pm.main.controller.rsp.CommodityDetail;
import com.pm.main.controller.rsp.HotCommodityRsp;
import com.pm.main.infrastructure.product.ProductPO;
import com.pm.main.infrastructure.product.ProductRepository;
import com.pm.main.infrastructure.product.ProductValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * Created by cjwfuture on 2021/6/6
 */
@RestController
@Api(tags = "商品信息")
@RequestMapping("commodity")
public class CommodityController {

    @Resource
    private ProductRepository productRepository;

    @ApiOperation("关键字搜索")
    @GetMapping("kw")
    public Flux<ProductValue> searchByKw(@RequestParam("kw") String kw,
                                         @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                         @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        return Flux.empty();
    }

    @ApiOperation("关键字搜索历史")
    @GetMapping("kw/history")
    public Flux<ProductValue> historyOfSearchByKw() {
        return Flux.empty();
    }

    @ApiOperation("热销商品")
    @PostMapping("list/hot")
    public Flux<HotCommodityRsp> listOfHot(@RequestBody CommoditySearchReq searchReq) {
        return productRepository.listOfHot(searchReq);
    }

    @ApiOperation("商品列表")
    @PostMapping("list")
    public Flux<HotCommodityRsp> list(@RequestBody CommoditySearchReq searchReq) {
        return Flux.empty();
    }

    @ApiOperation("商品详情")
    @GetMapping("{id}")
    public Mono<CommodityDetail> detail(@PathVariable("id") Long id) {
        return Mono.empty();
    }

    @PostMapping
    public Mono<ProductPO> add(@RequestBody ProductPO productPO) {
        return productRepository.add(productPO);
    }
}
